<?php
set_time_limit(0);
dl("php_sdl.dll");

define('APP_TITLE', '03 - Image movement');

// Start SDL engine with VIDEO submodule
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
	trigger_error('SDL can not be initialized. Exiting.');
	exit(1);
}

// Create a Window of 640x480, 16 bits of depth
$screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);
if(is_null($screen)) {
	trigger_error('Unable to create a new Window with the desired arguments.');
	exit(1);
}

SDL_WM_SetCaption(APP_TITLE, APP_TITLE);

// Load a BMP image from filesystem
$img = SDL_LoadBMP('agent.bmp');
if(is_null($img)) {
	trigger_error('Unable to load the specified image.');
	exit(1);
}

// Define the original destination for the image on the screen
$dest = array(
	'x' => 0,
	'y' => 100,
	'w' => 80,
	'h' => 80
);

// Animate the image from left to right of the screen
for($i = 0; $i < 640; $i++) {
	$dest['x'] = $i;
	SDL_BlitSurface($img, null, $screen, $dest);

	// Refresh the whole screen
	SDL_flip($screen);
}

// Free resources
SDL_FreeSurface($img);

// Stop SDL engine
SDL_Quit();

?>
